Conditions | 1 |
Paths | 1 |
Total Lines | 88 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
14 | function(data) { |
||
15 | let sv = this; |
||
16 | sv.hoverElement = ''; |
||
17 | sv.export = ''; |
||
18 | sv.player = {}; |
||
19 | sv.loading = true; |
||
20 | sv.processingOffline = false; |
||
21 | sv.offlineCyclesTotal = 0; |
||
22 | sv.offlineCyclesCurrent = 0; |
||
23 | sv.cancelOffline = false; |
||
24 | sv.toast = []; |
||
25 | sv.isToastVisible = false; |
||
26 | let newElements = []; |
||
27 | let updateFunctions = {}; |
||
28 | sv.reactionsCache = {}; |
||
29 | sv.redoxesCache = {}; |
||
30 | |||
31 | sv.deleteToast = function(currentTs, eventTs) { |
||
32 | if(currentTs-eventTs >= 350){ |
||
33 | sv.toast.shift(); |
||
34 | if (sv.toast.length > 0) { |
||
35 | sv.isToastVisible = true; |
||
36 | window.requestAnimationFrame((ts) => sv.removeToast(ts, performance.now())); |
||
|
|||
37 | } |
||
38 | }else{ |
||
39 | window.requestAnimationFrame((ts) => sv.deleteToast(ts, eventTs)); |
||
40 | } |
||
41 | }; |
||
42 | |||
43 | sv.removeToast = function(currentTs, eventTs) { |
||
44 | if(currentTs-eventTs >= 2500){ |
||
45 | sv.isToastVisible = false; |
||
46 | window.requestAnimationFrame((ts) => sv.deleteToast(ts, performance.now())); |
||
47 | }else{ |
||
48 | window.requestAnimationFrame((ts) => sv.removeToast(ts, eventTs)); |
||
49 | } |
||
50 | }; |
||
51 | |||
52 | sv.addToast = function (t) { |
||
53 | sv.toast.push(t); |
||
54 | if (sv.toast.length === 1) { |
||
55 | sv.isToastVisible = true; |
||
56 | window.requestAnimationFrame((ts) => sv.removeToast(ts, performance.now())); |
||
57 | } |
||
58 | }; |
||
59 | |||
60 | sv.init = function() { |
||
61 | sv.hoverElement = ''; |
||
62 | sv.export = ''; |
||
63 | sv.toast = []; |
||
64 | sv.isToastVisible = false; |
||
65 | newElements = []; |
||
66 | }; |
||
67 | |||
68 | sv.hasNew = function(entry) { |
||
69 | return newElements.indexOf(entry) !== -1; |
||
70 | }; |
||
71 | |||
72 | sv.addNew = function(entry) { |
||
73 | newElements.push(entry); |
||
74 | }; |
||
75 | |||
76 | sv.removeNew = function(entry) { |
||
77 | if (newElements.indexOf(entry) !== -1) { |
||
78 | newElements.splice(newElements.indexOf(entry), 1); |
||
79 | } |
||
80 | }; |
||
81 | |||
82 | sv.elementHasNew = function(element) { |
||
83 | let includes = data.elements[element].includes; |
||
84 | for (let key in includes) { |
||
85 | if (sv.hasNew(includes[key])) { |
||
86 | return true; |
||
87 | } |
||
88 | } |
||
89 | return false; |
||
90 | }; |
||
91 | |||
92 | sv.registerUpdate = function(name, func){ |
||
93 | updateFunctions[name] = func; |
||
94 | }; |
||
95 | |||
96 | sv.update = function(player){ |
||
97 | for(let func in updateFunctions){ |
||
98 | updateFunctions[func](player); |
||
99 | } |
||
100 | }; |
||
101 | }]); |
||
102 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.